function output = num2grid(m, x)  % Convert input numbers to grid points
    x = reshape(x, [], 1);
    m = reshape(m, [], 1);
    k = size(m, 1);
    r = [];
    for j = 1:k
        r = [rem(x, m(j)) r];
        x = floor(x / m(j));
    end
    % Yield n-th elements, where n ranges over x, in the equi-distributed grid of [0, 1]^4 with size m^4.
    output = r / diag(m-1);
end